//@author A0084556W

package Database;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

import Main.ManageItem;


public class BudgetDatabase {
	private final String datapath = System.getProperty("user.dir") + "\\src\\Database\\";
	private final String filepath = datapath + "budget.txt";


	public void writeArrayToFile(double[][] budget) throws IOException{
		PrintStream ps;
		try {
			ps = new PrintStream(new FileOutputStream(filepath));
			for(int row=0;row < budget.length;row++){
				for(int col=0; col < budget[row].length;col++){
					double s = budget[row][col];
					ps.println(s);
				}
			}
			ps.close();
		} catch (FileNotFoundException e) {
			System.out.println(e.getMessage());
		}
	}

	public double[][] readArrayFromFile ( ) throws IOException{
		Scanner s = null;
		double [][] tempBudget = new double[15][13];
		try {
			s = new Scanner(new BufferedReader(new FileReader(filepath)));

			for(int row=0;row < tempBudget.length;row++){
				for(int col=0; col < tempBudget[row].length;col++){
					tempBudget[row][col] = s.nextDouble();

				}
			}
		}
			
		finally {
				if (s != null) {
					s.close();
				}
			}
			return tempBudget;
		}
	}
